package com.zkr.kqsx.conterllor;


import com.zkr.kqsx.model.KQSXAddVo;
import com.zkr.kqsx.model.KQSXSelectVo;
import com.zkr.kqsx.model.KQSXUpdateStatusVo;
import com.zkr.kqsx.model.KQSXUpdateVo;
import com.zkr.kqsx.service.KQSXService;
import com.zkr.util.ResultBuilderVo;
import com.zkr.util.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * Created by lenovo on 2021/1/13.
 */
@RestController
@CrossOrigin
public class KQSXConterllor {

    @Autowired
    private KQSXService kqsxService;


    /**
     * 分页
     * @param kqsxSelectVo
     * @return
     */
    @PostMapping("pickingArea/queryPage")
    public ResultVo queryPage(@RequestBody KQSXSelectVo kqsxSelectVo){
        return kqsxService.queryPage(kqsxSelectVo);
    }


    /**
     * 添加
     */
    @PostMapping("pickingArea/add")
    public ResultVo add(@RequestBody @Valid KQSXAddVo kqsxAddVo,BindingResult bindingResult){
        if (bindingResult.hasErrors()){
            return ResultBuilderVo.error(bindingResult.getFieldError().getDefaultMessage());
        }
        return kqsxService.add(kqsxAddVo);
    }


    /**
     * 修改启用禁用接口
     * @param
     * @param bindingResult
     * @return
     */
    @PostMapping("pickingArea/updateStatus")
    public ResultVo updateStatus(@RequestBody @Valid KQSXUpdateStatusVo kqsxUpdateStatusVo, BindingResult bindingResult){
        if (bindingResult.hasErrors()){
            return ResultBuilderVo.error(bindingResult.getFieldError().getDefaultMessage());
        }
        return kqsxService.updateStatus(kqsxUpdateStatusVo);
    }


    /**
     * 修改
     */
    @PostMapping("pickingArea/update")
    public ResultVo update(@RequestBody @Valid KQSXUpdateVo kqsxUpdateVo, BindingResult bindingResult){
        if (bindingResult.hasErrors()){
            return ResultBuilderVo.error(bindingResult.getFieldError().getDefaultMessage());
        }
        return kqsxService.update(kqsxUpdateVo);
    }

}








